package com.yixun.qfbao.response.premisesdynamic;
/**
 * @author zilong.liu
 * @date 2020-9-10
 * 	楼盘动态列表返回实体类
 */

import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import com.yixun.qfbao.response.premises.detail.UrlInfo;
import com.yixun.qfbao.response.premises.detail.util.SplitHtmlUtil;
import com.yixun.qfbao.util.StringUtil;
import com.yixun.qfbao.xf.model.PremisesDynamic;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class PremisesDynamicResDto {

	@ApiModelProperty(value = "动态")
	private Long id;
	
	@ApiModelProperty(value = "时间")
	private String updateTime;
	
	@ApiModelProperty(value = "标题")
	private String title;
	
	@ApiModelProperty(value = "视频以及图片信息集合")
	private List<UrlInfo> urlInfoList;
	
	@ApiModelProperty(value = "内容")
	private String content;
	
	@ApiModelProperty(value = "楼盘名称")
	private String premisesName;
	
	@ApiModelProperty(value = "省")
	private String provName;
	
	@ApiModelProperty(value = "市")
	private String cityName;
	
	@ApiModelProperty(value = "区")
	private String areaName;
	
	@ApiModelProperty(value = "最低价格")
	private BigDecimal minPrice;
	
	@ApiModelProperty(value = "驻守人员电话")
	private String caseMemberPhone;
	
	@ApiModelProperty(value = "楼盘ID")
	private Long premisesId;
	
	public PremisesDynamicResDto() {
		
	}
	
	@SuppressWarnings("unchecked")
	public PremisesDynamicResDto(PremisesDynamic premisesDynamic) {
		this.id = premisesDynamic.getId();
		this.updateTime = new SimpleDateFormat("yyyy.MM.dd HH:mm").format(premisesDynamic.getUpdateTime());
		this.title = premisesDynamic.getTitle();
//		Map<String, Object> remarkMap;
		Map<String, Object> contentMap;
		try {
			contentMap = new SplitHtmlUtil().splitHtml(URLDecoder.decode(premisesDynamic.getContent(), "utf-8"));
		} catch (Exception e) {
			contentMap = new SplitHtmlUtil().splitHtml(premisesDynamic.getContent());
		}
//		try {
//			remarkMap = new SplitHtmlUtil().splitHtml(URLDecoder.decode(premisesDynamic.getRemark(), "utf-8"));
//		} catch (Exception e) {
//			remarkMap = new SplitHtmlUtil().splitHtml(premisesDynamic.getRemark());
//		}
		if(StringUtils.isNotBlank((String) contentMap.get("content"))) {
			this.content = (String) contentMap.get("content");
		}
		if(!CollectionUtils.isEmpty((List<UrlInfo>)contentMap.get("urlInfoList"))) {
			this.urlInfoList = (List<UrlInfo>)contentMap.get("urlInfoList");
		}
		SplitHtmlUtil.getRealUrlInfoList(urlInfoList);
		
		this.premisesName = premisesDynamic.getPremisesName();
		this.provName = premisesDynamic.getProvName();
		this.cityName = premisesDynamic.getCityName();
		this.areaName = premisesDynamic.getAreaName();
		List<BigDecimal> prices = StringUtil.getMinOrMaxFromSeprateString(
				premisesDynamic.getAveragePrice(), ",", 1);
		if(!CollectionUtils.isEmpty(prices)) {
			this.minPrice = prices.get(0);
		}
		if(StringUtils.isNotBlank(premisesDynamic.getCaseMemberPhone())) {
			this.caseMemberPhone = premisesDynamic.getCaseMemberPhone();
		}
		this.premisesId = premisesDynamic.getPremisesId();
	}
	
	
	public PremisesDynamicResDto(PremisesDynamic premisesDynamic , boolean detailFlag) {
		this.id = premisesDynamic.getId();
		this.updateTime = new SimpleDateFormat("yyyy.MM.dd HH:mm").format(premisesDynamic.getUpdateTime());
		this.title = premisesDynamic.getTitle();
		try {
			this.content = URLDecoder.decode(premisesDynamic.getContent(), "utf-8");
		} catch (Exception e) {
			this.content = premisesDynamic.getContent();
		}
		this.premisesName = premisesDynamic.getPremisesName();
		this.provName = premisesDynamic.getProvName();
		this.cityName = premisesDynamic.getCityName();
		this.areaName = premisesDynamic.getAreaName();
		this.minPrice = StringUtil.getMinOrMaxFromSeprateString(
				premisesDynamic.getAveragePrice(), ",", 1).get(0);
		if(StringUtils.isNotBlank(premisesDynamic.getCaseMemberPhone())) {
			this.caseMemberPhone = premisesDynamic.getCaseMemberPhone();
		}
		this.premisesId = premisesDynamic.getPremisesId();
	}
	
}
